home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / comm / irc / AmirxRebol.lha / amirxrebol / rebol / bldrates.r next >
Encoding:
Text File  |  1998-10-24  |  2.0 KB  |  92 lines

  1. REBOL [
  2.    Title:   "Build Currency conversion table"
  3.    Author:  "Dick Whiting"
  4.    Email:   dwhiting@europa.com
  5.    Date:    09-Oct-1998
  6.    File:    %bldrates.r
  7.    Purpose: {
  8.       Build a currency conversion series and saves to disk
  9.    }
  10.    Comment: {
  11.  
  12.       Reads the currency table at pacific.commerce and parses
  13.       it into a REBOL series. The series is then saved as a   
  14.       file and can be used with convert.r for doing currency
  15.       conversions and with currency.r for locating currencies
  16.       by partial string lookups, e.g. "finn" finds FIM Finnish...
  17.  
  18.       The output filename is hardcoded as %rates.table
  19.  
  20.       If run with a first argument of "PIPE" then writes a message
  21.       to the second argument which should be PIPE:some.pipe.name
  22.       
  23.    }
  24. ]
  25.  
  26.  
  27.    if pick rebol/args 1 [
  28.       mode: pick rebol/args 1
  29.       pipe: make file! pick rebol/args 2
  30.    ]
  31.    else [
  32.       mode:  "NONE"
  33.       pipe:  "NONE"
  34.    ]
  35.  
  36.    t1: make time! fourth now
  37.  
  38.    rpage: read http://pacific.commerce.ubc.ca/xr/rates.html
  39.  
  40.    rpage: find rpage "<td align"
  41.  
  42.    rtabl: ["USD" "U.S. Dollar" "1"]
  43.  
  44.    while [found? find rpage "<tt>"] [
  45.  
  46.       code:  copy/part skip (find rpage "<tt>") 4 find rpage "</tt>"
  47.  
  48.       rpage: find rpage "left>"  
  49.       name:  copy/part skip rpage 5 find rpage "</td>"
  50.  
  51.       loop 3 [rpage: skip (find rpage "right>") 6]
  52.  
  53.       exch:  copy/part rpage find rpage "</td>"
  54.  
  55.       if code <> "USD" [
  56.          insert tail rtabl reduce [code name exch]
  57.       ]
  58.    ]
  59.  
  60.    rtabl: head rtabl
  61.  
  62.    save %rates.table rtabl
  63.  
  64.    t2: make time! fourth now
  65.  
  66.    entries: length? rtabl
  67.  
  68.    if entries > 3 [
  69.       if mode = "PIPE" [
  70.          write pipe "Done building rates table"
  71.          write newline
  72.          quit
  73.       ]
  74.       else [
  75.          print "Done building rates table"
  76.          print ["Elapsed time: " t2 - t1]
  77.          halt
  78.       ]
  79.    ]
  80.    else [
  81.       if mode = "PIPE" [
  82.          write pipe "Bldrates.r unsuccessful"
  83.          write newline
  84.          quit
  85.       ]
  86.       else [
  87.          print "Bldrates.r unsuccessful"
  88.          halt
  89.       ]
  90.    ]
  91.  
  92.